package com.xmlt.ui.xmltutils;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

import com.xmlt.core.template.contentgenerators.IContentGenerator;
import com.xmlt.core.template.contentgenerators.IContentGeneratorFactory;
import com.xmlt.core.template.instance.Instance;

public class XMLGeneratorFactory implements IContentGeneratorFactory {

	@Override
	public Class<?> getTargetClass() {
		return Document.class;
	}

	@Override
	public IContentGenerator getContentGenerator() {
		return new IContentGenerator() {
			
			@Override
			public Class<?> getTargetClass() {
				return Document.class;
			}
			
			@Override
			public Object getContent(Instance instance) {
				DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
				DocumentBuilder db = null;
				try {
					db = dbf.newDocumentBuilder();
				} catch (ParserConfigurationException e) {
					e.printStackTrace();
				}
				if (db != null) {
					Document document = db.newDocument();
					return document;
				}
				
				return null;
			}
		};
		
	}

}
